﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OS
{
    static class QueueManager
    {
        //Proccess queues
        public static Queue<ProcessControlBlock> pcbQueue;
        public static Queue<ProcessControlBlock> readyQueue;
        public static Queue<ProcessControlBlock> swapQueue;
        public static Queue<ProcessControlBlock> ioQueue;
        public static Queue<ProcessControlBlock> terminatedQueue;

        //Buffer queues
        public static Queue<Buffer> ebQueue;
        public static Queue<IFBBuffer> ifbQueue;
        public static Queue<Buffer> ofbQueue;

        /// <summary>
        /// Initializes the queues and loads the empty buffer queue with the ten buffers.
        /// </summary>
        public static void Initialize()
        {
            pcbQueue = new Queue<ProcessControlBlock>();
            readyQueue = new Queue<ProcessControlBlock>();
            swapQueue = new Queue<ProcessControlBlock>();
            ioQueue = new Queue<ProcessControlBlock>();
            terminatedQueue = new Queue<ProcessControlBlock>();
            ebQueue = new Queue<Buffer>();
            ifbQueue = new Queue<IFBBuffer>();
            ofbQueue = new Queue<Buffer>();

            //load the ten empty buffers
            for (int i = 0; i < 10; i++)
            {
                ebQueue.Enqueue(new Buffer());
            }
        }

        /// <summary>
        /// Checks to see if the ready queue is empty
        /// </summary>
        /// <returns>Boolean value for if readyQueue is empty</returns>
        public static bool IsPCBQueueEmpty()
        {
            return pcbQueue.Count == 0;
        }

        /// <summary>
        /// Checks to see if the ready queue is empty
        /// </summary>
        /// <returns>Boolean value for if readyQueue is empty</returns>
        public static bool IsReadyQueueEmpty()
        {
            return readyQueue.Count == 0;
        }

        /// <summary>
        /// Checks to see if the swap queue is empty
        /// </summary>
        /// <returns>Boolean value for if swapQueue is empty</returns>
        public static bool IsSwapQueueEmpty()
        {
            return swapQueue.Count == 0;
        }

        /// <summary>
        /// Checks to see if the IO queue is empty
        /// </summary>
        /// <returns>Boolean value for if ioQueue is empty</returns>
        public static bool IsIOQueueEmpty()
        {
            return ioQueue.Count == 0;
        }

        /// <summary>
        /// Checks to see if the terminated queue is empty
        /// </summary>
        /// <returns>Boolean value for if terminatedQueue is empty</returns>
        public static bool IsTerminatedQueueEmpty()
        {
            return terminatedQueue.Count == 0;
        }

        /// <summary>
        /// Checks to see if the eb queue is empty
        /// </summary>
        /// <returns>Boolean value for if ebQueue is empty</returns>
        public static bool IsEBQueueEmpty()
        {
            return ebQueue.Count == 0;
        }

        /// <summary>
        /// Checks to see if the ifb queue is empty
        /// </summary>
        /// <returns>Boolean value for if ifbQueue is empty</returns>
        public static bool IsIFBQueueEmpty()
        {
            return ifbQueue.Count == 0;
        }

        /// <summary>
        /// Checks to see if the ofb queue is empty
        /// </summary>
        /// <returns>Boolean value for if ofbQueue is empty</returns>
        public static bool IsOFBQueueEmpty()
        {
            return ofbQueue.Count == 0;
        }
        
        /// <summary>
        /// Checks to see if all the PCB queues are empty
        /// </summary>
        /// <returns>Boolean stating if all PCBs are empty</returns>
        public static bool AllQueuesEmpty()
        {
            return IsIOQueueEmpty() && IsPCBQueueEmpty() && IsReadyQueueEmpty() && IsSwapQueueEmpty() && IsTerminatedQueueEmpty();
        }
    }
}